using System;
using System.Collections.Generic;
using System.Text;
using Web.Core.Providers;
using System.Collections;

namespace Web.Core.Objects
{
    public class Members
    {
        public static int InsertMember(Member mem)
        {
            return DataProvider.GetInstance().InsertDeleteUpdateMember(mem, GlobalStorage.Action.Insert);
        }

        public static int DeleteMember(Member mem)
        {
            return DataProvider.GetInstance().InsertDeleteUpdateMember(mem, GlobalStorage.Action.Delete);
        }

        public static int UpdateMember(Member mem)
        {
            return DataProvider.GetInstance().InsertDeleteUpdateMember(mem, GlobalStorage.Action.Update);
        }

        public static Member GetMemberByLogin(string email, string password)
        {
            if (email != "" && password != "")
            {
                ArrayList arrMem = DataProvider.GetInstance().GetMembers(new Member(0, email, password, GlobalStorage.Sex.Both, "", "", "", "", "", "", "", "", new Role(0, ""), ""), 1, 0, "member_id", GlobalStorage.Order.Ascend);
                if (arrMem.Count > 0)
                    return arrMem[0] as Member;
            }
            return null;
        }

        public static Member GetMemberByEmail(string email)
        {
            if (email != "")
            {
                ArrayList arrMem = DataProvider.GetInstance().GetMembers(new Member(0, email, "", GlobalStorage.Sex.Both, "", "", "", "", "", "", "", "", new Role(0, ""), ""), 1, 0, "member_id", GlobalStorage.Order.Ascend);
                if (arrMem.Count > 0)
                    return arrMem[0] as Member;
            }
            return null;
        }

        public static Member GetMemberByEmailAndSecretAnswer(string email, string secretQuestion, string secretAnswer)
        {
            if (email != "" && secretQuestion != "" && secretAnswer != "")
            {
                ArrayList arrMem = DataProvider.GetInstance().GetMembers(new Member(0, email, "", GlobalStorage.Sex.Both, "", "", "", "", "", "", secretQuestion, secretAnswer, new Role(0, ""), ""), 1, 0, "member_id", GlobalStorage.Order.Ascend);
                if (arrMem.Count > 0)
                    return arrMem[0] as Member;
            }
            return null;
        }

        public static int CountAllMembers()
        {
            return DataProvider.GetInstance().CountMembers(new Member(0, "", "", GlobalStorage.Sex.Both, "", "", "", "", "", "", "", "", new Role(0, ""), ""));
        }

        public static ArrayList GetMembersByPage(int pageNum, int pageSize)
        {
            return DataProvider.GetInstance().GetMembers(new Member(0, "", "", GlobalStorage.Sex.Both, "", "", "", "", "", "", "", "", new Role(0, ""), ""), pageNum, pageSize, "member_id", GlobalStorage.Order.Ascend);
        }

        public static Member GetMemberByID(int id)
        {            
            ArrayList arr = DataProvider.GetInstance().GetMembers(new Member(id, "", "", GlobalStorage.Sex.Both, "", "", "", "", "", "", "", "", new Role(0, ""), ""), 1, 0, "member_id", GlobalStorage.Order.Ascend);
            if (arr.Count > 0)
                return arr[0] as Member;
            else
                return null;
        }
        public static ArrayList GetMembers(Member mem, int pageNum, int pageSize)
        {
            return DataProvider.GetInstance().GetMembersSearch(mem, pageNum, pageSize, "member_id", GlobalStorage.Order.Ascend);
        }
        public static int CountAllMembers(Member mem)
        {
            return DataProvider.GetInstance().CountMembersSearch(mem);
        }
    }
}
